import { Component, OnInit } from '@angular/core';
import { ElementRef, ViewChild, AfterViewInit, Renderer } from '@angular/core';
import { ListService } from '../_common/_service/list.service';
import { Task } from '../_common/_model/task';
import { User } from '../_common/_model/user';

@Component({
  selector: 'app-my-day',
  templateUrl: './my-day.component.html',
  styleUrls: ['./my-day.component.less', '../_common/new-todo.less']
})
export class MyDayComponent implements OnInit {
  bgurl: string;
  newTask: string;
  myDayTasks: Task[];
  now: string;
  focused = false;  // 控制添加待办事项的样式

  constructor(
    private _listService: ListService) { }

  ngOnInit(): void {
    this.getTodayTasks();
    this.now = this.getDate();
  }

  getTodayTasks() {
    if (!this._listService.lists) {
      setTimeout(() => {
        this.getTodayTasks();
      }, 300);
    } else {
      this.myDayTasks = this._listService.getTodayTasks();
    }
  }

  // 今日任务输入框聚焦与blur
  focus(): void {
    this.focused = true;
  }
  blur(): void {
    this.focused = false;
  }

  getDate() {
    const date = new Date();
    const week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    return `${date.getMonth() + 1}月${date.getDate()}日, ${week[date.getDay()]}`;
  }

  // addTodayTask(): void {
  //   if (this.newTask.trim()) {
  //     const todayTask: Task = {
  //       id: this.taskService.getTasks().length - 1,
  //       todo: this.newTask.trim(),
  //       isDone: false,
  //       today: true,
  //       creationTime: new Date().toString(),
  //       deadline: null,
  //       notes: null,
  //       listId: 1
  //     };
  //     this.myDayTasks.push(todayTask);
  //     this.newTask = '';
  //   }
  // }

}
